package org.manager.generic.initalize;

import javax.annotation.Resource;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.orm.hibernate3.HibernateTemplate;
import org.springframework.stereotype.Component;

@Component
public class InitCache implements InitializingBean {
	private static final Log log = LogFactory.getLog(InitCache.class);
	
	@Resource(name="hibernateTemplate")
	private HibernateTemplate htmp;
	
	public void afterPropertiesSet() throws Exception {
		log.debug("开始初始化二级缓存................");
		//TODO:将需要进行二级缓存的对象进行填充.
		Session session = htmp.getSessionFactory().openSession();
		Transaction t = session.beginTransaction();
		session.createQuery("from Menu").list();
		session.createQuery("from SystemRole").list();
		session.createQuery("from UserAccount").list();
		session.createQuery("from Property").list();
		session.createQuery("from Properties").list();
		session.createQuery("from SysUnits").list();
		session.createQuery("from ClassHours").list();
		session.createQuery("from Function").list();
		t.commit();

	}
}
